/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import ClasesAModificar.AcontecimientoModificar;
import javax.swing.JOptionPane;
import src.Core;

/**
 *
 * @author Strauzen
 */
public class VentanaConsultaAcontecimiento extends javax.swing.JFrame {

    Ventana1 v1;
    
    /**
     * Creates new form VentanaConsultaAcontecimiento
     */
    public VentanaConsultaAcontecimiento(Ventana1 v1) {
        this.v1 = v1;
        initComponents();
    }

    private boolean correcto(){
        try{
            if(!this.jTextField_vacFechaCom.getText().equals(""))
                Integer.parseInt(this.jTextField_vacFechaCom.getText());
            if(!this.jTextField_vacFechaFin.getText().equals(""))
                Integer.parseInt(this.jTextField_vacFechaFin.getText());
            
            if(!this.jTextField_vacFechaCom.getText().equals("") && this.jTextField_vacFechaCom.getText().length() != 8)
                throw new Exception();            
            if(!this.jTextField_vacFechaFin.getText().equals("") && this.jTextField_vacFechaFin.getText().length() != 8)
                throw new Exception();
                
            return true;
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Por favor rellene las fechas de la siguiente manera:\n"
                    + "ej. 20120101 siendo los 4 primeros numeros el año, los dos siguientes el mes\n"
                    + "y los dos ultimos el día\n\n");
            return false;
        }
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel_vacNombre = new javax.swing.JLabel();
        jTextField_vacNombre = new javax.swing.JTextField();
        jLabel_vacDescripcion = new javax.swing.JLabel();
        jTextField_vacDescripcion = new javax.swing.JTextField();
        jLabel_vacFechaCom = new javax.swing.JLabel();
        jTextField_vacFechaCom = new javax.swing.JTextField();
        jLabel_vacFechaFin = new javax.swing.JLabel();
        jTextField_vacFechaFin = new javax.swing.JTextField();
        jButton_vacTerminar = new javax.swing.JButton();
        jTextField_vcaFichero = new javax.swing.JTextField();
        jLabel_vcaFichero = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jLabel_vacNombre.setText("Nombre");

        jLabel_vacDescripcion.setText("Descripcion");

        jLabel_vacFechaCom.setText("Fecha de Comienzo");

        jLabel_vacFechaFin.setText("Fecha de Finalizacion");

        jButton_vacTerminar.setText("Terminar");
        jButton_vacTerminar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_vacTerminarMouseClicked(evt);
            }
        });

        jLabel_vcaFichero.setText("Fichero");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vacNombre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vacNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vacDescripcion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vacDescripcion, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vacFechaFin)
                    .addComponent(jLabel_vacFechaCom))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_vacFechaCom, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                    .addComponent(jTextField_vacFechaFin, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(157, Short.MAX_VALUE)
                .addComponent(jButton_vacTerminar)
                .addGap(148, 148, 148))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel_vcaFichero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField_vcaFichero, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel_vacNombre)
                    .addComponent(jTextField_vacNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vacDescripcion)
                    .addComponent(jTextField_vacDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vacFechaCom)
                    .addComponent(jTextField_vacFechaCom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vacFechaFin)
                    .addComponent(jTextField_vacFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel_vcaFichero)
                    .addComponent(jTextField_vcaFichero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton_vacTerminar)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_vacTerminarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_vacTerminarMouseClicked
// TODO add your handling code here:
        if (correcto()) {
            AcontecimientoModificar AC = new AcontecimientoModificar(-1, jTextField_vacNombre.getText(),
                                                                     jTextField_vacDescripcion.getText(), -1,
                                                                     Integer.valueOf(jTextField_vacFechaFin.getText()), Integer.valueOf(jTextField_vacFechaCom.getText()),
                                                                     "");
            VentanaConsultaEleccion vce = new VentanaConsultaEleccion(v1);
            String acont = Core.buscaEnLaBDPorAcontecimiento(AC);
            vce.modificarTexto(acont);
            vce.setVisibleVCETipo(false);
            vce.setPadre(3);
            vce.setVisible(true);
            this.setVisible(false);
            this.dispose();
        }
    }//GEN-LAST:event_jButton_vacTerminarMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_vacTerminar;
    private javax.swing.JLabel jLabel_vacDescripcion;
    private javax.swing.JLabel jLabel_vacFechaCom;
    private javax.swing.JLabel jLabel_vacFechaFin;
    private javax.swing.JLabel jLabel_vacNombre;
    private javax.swing.JLabel jLabel_vcaFichero;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField_vacDescripcion;
    private javax.swing.JTextField jTextField_vacFechaCom;
    private javax.swing.JTextField jTextField_vacFechaFin;
    private javax.swing.JTextField jTextField_vacNombre;
    private javax.swing.JTextField jTextField_vcaFichero;
    // End of variables declaration//GEN-END:variables
}
